package com.devilvan.betrice.common;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author Evad.Wu
 * @Description 统一结果返回类
 * @date 2022-07-16
 */
@Data
@NoArgsConstructor
@Schema(description = "统一结果返回类")
@SuppressWarnings(value = "all")
public class BetriceResultVo<T> {
    @Schema(description = "返回编码")
    private String code;
    @Schema(description = "返回消息")
    private String msg;
    @Schema(description = "是否成功")
    private boolean success = false;
    @Schema(description = "返回数据")
    private T data;
    @Schema(description = "操作行数")
    private Integer handleCount = 0;

    public BetriceResultVo(boolean success) {
        this.success = success;
    }

    public BetriceResultVo<T> result(String code) {
        return result(code, null);
    }

    public BetriceResultVo<T> result(String code, String msg) {
        return result(code, msg, null);
    }

    public BetriceResultVo<T> result(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        return this;
    }

    public BetriceResultVo<T> result(BetriceResultCode constant, String msg) {
        this.success = constant.isSuccess();
        this.code = constant.getCode();
        return this.result(code, msg);
    }

    public BetriceResultVo<T> result(BetriceResultCode constant, String msg, T data) {
        this.success = constant.isSuccess();
        this.code = constant.getCode();
        this.msg = msg;
        this.data = data;
        return this;
    }
}
